/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cpa_autorizados.java
 *
 * Created on 26/05/2010, 22:41:32
 */

package siga.visao_cpa;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import siga.banco.conexao;
import siga.banco.unimestre;
import siga.visao_busca.buscaCpaAvaliacao;
import siga.visao_busca.buscaUniCurso;
import siga.visao_busca.buscaUniTurma;
import siga.visao_busca.buscaVer;
import siga.visao.index;
import siga.visao.verErros;

/**
 *
 * @author rafaelfrasson
 */
public class cpa_autorizados extends javax.swing.JInternalFrame {
    Object[] JOopcoes = {"Sim","Não"};
    private static List sql = new ArrayList();
    private static List sql2 = new ArrayList();
    /** Creates new form cpa_autorizados */
    public cpa_autorizados() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        barraFerramentaFonecedor = new javax.swing.JToolBar();
        btNovo = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();
        btRemover = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        btSair = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jtfCod_avaliacao = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jtfDesc_avaliacao = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfCod_pessoa = new javax.swing.JTextField();
        jtfDesc_pessoa = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfCod_curso = new javax.swing.JTextField();
        jtfCod_turma = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jtfAnoSemestre = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("CPA :: Autorizados");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/cpa_user.png"))); // NOI18N

        barraFerramentaFonecedor.setFloatable(false);
        barraFerramentaFonecedor.setRollover(true);
        barraFerramentaFonecedor.setName("barraFerramentaFonecedor"); // NOI18N

        btNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/novo_32x32.png"))); // NOI18N
        btNovo.setMnemonic('N');
        btNovo.setText("Novo");
        btNovo.setToolTipText("Inseri um Novo Cadastro");
        btNovo.setFocusable(false);
        btNovo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btNovo.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btNovo.setName("btNovo"); // NOI18N
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btNovo);

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/cancelar_32x32.png"))); // NOI18N
        btCancelar.setMnemonic('C');
        btCancelar.setText("Cancelar");
        btCancelar.setToolTipText("Cancelar um Cadastro");
        btCancelar.setEnabled(false);
        btCancelar.setFocusable(false);
        btCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btCancelar.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btCancelar.setName("btCancelar"); // NOI18N
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btCancelar);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/salvar_32x32.png"))); // NOI18N
        btSalvar.setMnemonic('S');
        btSalvar.setText("Salvar");
        btSalvar.setToolTipText("Salvar um Cadastro");
        btSalvar.setEnabled(false);
        btSalvar.setFocusable(false);
        btSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btSalvar.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btSalvar.setName("btSalvar"); // NOI18N
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btSalvar);

        btRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/remover_32x32.png"))); // NOI18N
        btRemover.setMnemonic('R');
        btRemover.setText("Remover");
        btRemover.setToolTipText("Remove um Cadastro");
        btRemover.setEnabled(false);
        btRemover.setFocusable(false);
        btRemover.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btRemover.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btRemover.setName("btRemover"); // NOI18N
        btRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoverActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btRemover);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/buscar_32x32.png"))); // NOI18N
        jButton3.setText("Buscar");
        jButton3.setToolTipText("Busca somente Docentes");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(jButton3);

        btSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/sair_32x32.png"))); // NOI18N
        btSair.setMnemonic('S');
        btSair.setText("Sair");
        btSair.setToolTipText("Sair da Janela");
        btSair.setFocusable(false);
        btSair.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btSair.setMargin(new java.awt.Insets(2, 2, 2, 4));
        btSair.setName("btSair"); // NOI18N
        btSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairActionPerformed(evt);
            }
        });
        barraFerramentaFonecedor.add(btSair);

        jPanel1.setName("jPanel1"); // NOI18N

        jtfCod_avaliacao.setEnabled(false);
        jtfCod_avaliacao.setName("jtfCod_avaliacao"); // NOI18N

        jLabel1.setText("Avaliação:");
        jLabel1.setName("jLabel1"); // NOI18N

        jtfDesc_avaliacao.setEnabled(false);
        jtfDesc_avaliacao.setName("jtfDesc_avaliacao"); // NOI18N

        jLabel2.setText("Pessoa Unimestre:");
        jLabel2.setName("jLabel2"); // NOI18N

        jtfCod_pessoa.setEnabled(false);
        jtfCod_pessoa.setName("jtfCod_pessoa"); // NOI18N

        jtfDesc_pessoa.setEnabled(false);
        jtfDesc_pessoa.setName("jtfDesc_pessoa"); // NOI18N

        jLabel3.setText("Curso Unimestre:");
        jLabel3.setName("jLabel3"); // NOI18N

        jtfCod_curso.setEnabled(false);
        jtfCod_curso.setName("jtfCod_curso"); // NOI18N

        jtfCod_turma.setEnabled(false);
        jtfCod_turma.setName("jtfCod_turma"); // NOI18N

        jLabel4.setText("Turma Unimestre:");
        jLabel4.setName("jLabel4"); // NOI18N

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jButton4.setEnabled(false);
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jButton5.setEnabled(false);
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jButton6.setEnabled(false);
        jButton6.setName("jButton6"); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel5.setText("Ano/Semestre:");
        jLabel5.setName("jLabel5"); // NOI18N

        jtfAnoSemestre.setText("20102");
        jtfAnoSemestre.setEnabled(false);
        jtfAnoSemestre.setName("jtfAnoSemestre"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jtfCod_avaliacao, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDesc_avaliacao, javax.swing.GroupLayout.PREFERRED_SIZE, 497, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jtfCod_pessoa, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDesc_pessoa, javax.swing.GroupLayout.PREFERRED_SIZE, 497, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4))
                    .addComponent(jLabel4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jtfCod_curso, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtfCod_turma, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton5)
                                    .addComponent(jButton6))))
                        .addGap(40, 40, 40)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfAnoSemestre)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(122, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCod_avaliacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfDesc_avaliacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfCod_pessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfDesc_pessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton5)
                            .addComponent(jtfCod_curso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfCod_turma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButton6)))
                    .addComponent(jtfAnoSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Autorizado", "Situação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setMinWidth(80);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(1).setMinWidth(90);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(90);
        jTable1.getColumnModel().getColumn(1).setMaxWidth(90);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Curso", "Disciplina", "Professor"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane2.setViewportView(jTable2);
        jTable2.getColumnModel().getColumn(0).setMinWidth(80);
        jTable2.getColumnModel().getColumn(0).setPreferredWidth(80);
        jTable2.getColumnModel().getColumn(0).setMaxWidth(80);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraFerramentaFonecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 722, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(barraFerramentaFonecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed
        if(!jtfCod_avaliacao.getText().equals("")){
            btSalvar.setEnabled(!btSalvar.isEnabled());
            btCancelar.setEnabled(!btCancelar.isEnabled());
            btNovo.setEnabled(!btNovo.isEnabled());
            btRemover.setEnabled(false);
            GerenciaCampos();
            LimpaCampos();
        }else{
            JOptionPane.showMessageDialog(null, "Favor buscar uma Avaliação.","Alerta do Sistema",JOptionPane.INFORMATION_MESSAGE);
        }
}//GEN-LAST:event_btNovoActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        if(btCancelar.isEnabled()){
            if(!btNovo.isEnabled()){
                btSalvar.setEnabled(!btSalvar.isEnabled());
                btCancelar.setEnabled(!btCancelar.isEnabled());
                btNovo.setEnabled(!btNovo.isEnabled());
            }else{
                gerenciaBotao();
            }
            LimpaCampos();
            GerenciaCampos();
        }
}//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        if(!jtfCod_curso.getText().equals("")){
            try {
                int cont=0;
                unimestre.Conexao();
                unimestre.QueryGT("SELECT d.codigoaluno,p.ds_login, p.ds_senha FROM fichaindividual d " +
                        " inner join pessoas p on p.cd_pessoa=d.codigoaluno " +
                        " where d.anosemestre=" + jtfAnoSemestre.getText() + " and (d.situacao<>3 and d.situacao<>4 and d.situacao<>12) and d.turma like \"" + jtfCod_curso.getText() + "%\" group by d.codigoaluno");
                while (unimestre.rs.next()) {
                    String lg = (unimestre.rs.getString("ds_login")==null) ? "null" : unimestre.rs.getString("ds_login");
                    conexao.Inserir("insert into cpa_autorizados (cod_emp,cod_pessoa,login,senha,cod_avaliacao) " +
                            " values ("+index.cod_emp+","+unimestre.rs.getString("codigoaluno")+",\""+lg+"\",\""+unimestre.rs.getString("ds_senha")+"\","+jtfCod_avaliacao.getText()+")");
                }
                conexao.Query("select codigo, cod_pessoa from cpa_autorizados where cod_avaliacao="+jtfCod_avaliacao.getText()+" and cod_emp="+index.cod_emp);
                while(conexao.rs.next()){
                    sql.add(cont, conexao.rs.getString("cod_pessoa"));
                    sql2.add(cont, conexao.rs.getString("codigo"));
                    cont++;
                }
                for(int i=0; i<cont; i++){
                     unimestre.QueryGT("SELECT dm.codigoaluno, d.professor, d.disciplina, di.descricao, d.curso, p.nm_pessoa FROM diario_turmas d " +
                            " inner join pessoas p on p.cd_pessoa=d.professor " +
                            " inner join fichaindividual dm on dm.turma=d.turma and dm.anosemestre=d.anosemestre and dm.disciplina=d.disciplina " +
                            " inner join disciplinas di on di.codigo=d.disciplina and di.curso=d.curso " +
                            " where dm.codigoaluno="+sql.get(i)+" and d.anosemestre=" + jtfAnoSemestre.getText() + " and d.curso=" + jtfCod_curso.getText() + " and (dm.situacao<>3 and dm.situacao<>4 and dm.situacao<>12) group by d.disciplina,d.professor,dm.codigoaluno order by dm.codigoaluno");
                    while(unimestre.rs.next()){
                        conexao.Inserir("insert into cpa_curso (cod_autorizados,cod_emp,cod_curso,cod_professor,desc_professor,cod_disciplina,desc_disciplina) values("+sql2.get(i)+","+index.cod_emp+","+unimestre.rs.getString("curso")+","+unimestre.rs.getString("professor")+",\""+unimestre.rs.getString("nm_pessoa")+"\","+unimestre.rs.getString("disciplina")+",\""+unimestre.rs.getString("descricao")+"\");");
                    }

                }
                unimestre.FechaConexao();
                JOptionPane.showMessageDialog(null, "Cadastro de Autorizados terminado.","Alerta do Sistema",JOptionPane.INFORMATION_MESSAGE);
                listaAtuorizados();
                GerenciaCampos();
                LimpaCampos();
            } catch (SQLException ex) {
                verErros.setErro("(Salvar Autorizados): " + ex.getMessage());
            }
        }
}//GEN-LAST:event_btSalvarActionPerformed

    private void btRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverActionPerformed
//        if (JOptionPane.showOptionDialog(null, "Deseja remover este Grupo?\nEsta ação implica em remover todos os registros de Grupos aplicadas até o momento.", "Removendo Curso", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOopcoes, JOopcoes[0]) == JOptionPane.YES_OPTION) {
//            try {
//                conexao.stm.executeUpdate("delete from cpa_grupo where codigo="+" and cod_emp="+index.cod_emp+" and cod_avaliacao="+jtfCod_avaliacao.getText());
//            } catch (SQLException ex) {
//                verErros.setErro(ex.getMessage());
//            }
//        }
}//GEN-LAST:event_btRemoverActionPerformed

    @SuppressWarnings("static-access")
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        buscaCpaAvaliacao bca = new buscaCpaAvaliacao(null,true);
        bca.setLocation((index.tela.width-bca.getWidth())/2, (index.tela.height-bca.getHeight())/2);
        bca.setVisible(true);
        if(bca.bcpaa_finaliza){
            jtfCod_avaliacao.setText(bca.bcpaa_dados.get(0).toString());
            jtfDesc_avaliacao.setText(bca.bcpaa_dados.get(1).toString());
            bca.bcpaa_dados.clear();
            listaAtuorizados();
        }
}//GEN-LAST:event_jButton3ActionPerformed

    private void btSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairActionPerformed
        btCancelarActionPerformed(evt);
        setVisible(false);
        dispose();
}//GEN-LAST:event_btSairActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        buscaVer.setTipo("Unimestre");
        buscaVer bv = new buscaVer(null,true);
        bv.setLocation((index.tela.width-bv.getWidth())/2, (index.tela.height-bv.getHeight())/2);
        bv.setVisible(true);
        if(buscaVer.isConfirmaBusca()){
            jtfCod_pessoa.setText(index.LRpessoa.get(0).toString());
            jtfDesc_pessoa.setText(index.LRpessoa.get(1).toString());
        }
        index.LRpessoa.add(0, "");
        index.LRpessoa.add(1, "");
}//GEN-LAST:event_jButton4ActionPerformed

    @SuppressWarnings("static-access")
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        buscaUniCurso buc = new buscaUniCurso(null,true);
        buc.setLocation((index.tela.width-buc.getWidth())/2, (index.tela.height-buc.getHeight())/2);
        buc.setVisible(true);
        if(buc.buc_finaliza){
            jtfCod_curso.setText(buc.buc_dados.get(0).toString());
            buc.buc_dados.clear();
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    @SuppressWarnings("static-access")
    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        buscaUniTurma but = new buscaUniTurma(null,true);
        but.setLocation((index.tela.width-but.getWidth())/2, (index.tela.height-but.getHeight())/2);
        but.setVisible(true);
        if(but.but_finaliza){
            jtfCod_turma.setText(but.but_dados.get(0).toString());
            but.but_dados.clear();
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
       if(evt.getClickCount() == 2){
            listaCursos();
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void LimpaCampos(){
        jtfCod_curso.setText("");
    }

    private void GerenciaCampos(){
        jButton5.setEnabled(!jButton5.isEnabled());
    }

    private void gerenciaBotao(){
        btNovo.setEnabled(!btNovo.isEnabled());
        btCancelar.setEnabled(!btCancelar.isEnabled());
        btRemover.setEnabled(!btRemover.isEnabled());
        btSalvar.setEnabled(!btSalvar.isEnabled());
    }

    private void listaAtuorizados(){
        int i = jTable1.getRowCount();
        javax.swing.table.DefaultTableModel jtm = (javax.swing.table.DefaultTableModel)jTable1.getModel();
        for(int x=(i-1);x>=0; --x ){
            jtm.removeRow(x);
        }
        try {
            conexao.Query("select * from cpa_autorizados where cod_avaliacao="+jtfCod_avaliacao.getText()+" and cod_emp="+index.cod_emp+" order by codigo");
            while (conexao.rs.next()) {
                jtm.addRow(new Object[]{conexao.rs.getString("codigo"),conexao.rs.getString("cod_pessoa"),(conexao.rs.getString("cod_resposta").equals("0")) ? "Em Aberto" : "Resposta"});
            }
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }

    private void listaCursos(){
        int i = jTable2.getRowCount();
        javax.swing.table.DefaultTableModel jt = (javax.swing.table.DefaultTableModel)jTable1.getModel();
        javax.swing.table.DefaultTableModel jtm = (javax.swing.table.DefaultTableModel)jTable2.getModel();
        for(int x=(i-1);x>=0; --x ){
            jtm.removeRow(x);
        }
        try {
            conexao.Query("select * from cpa_curso where cod_autorizados="+jt.getValueAt(jTable1.getSelectedRow(), 0)+" and cod_emp="+index.cod_emp+" order by codigo");
            while (conexao.rs.next()) {
                jtm.addRow(new Object[]{conexao.rs.getString("cod_curso"),conexao.rs.getString("desc_disciplina"),conexao.rs.getString("desc_professor")});
            }
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar barraFerramentaFonecedor;
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btNovo;
    private javax.swing.JButton btRemover;
    private javax.swing.JButton btSair;
    private javax.swing.JButton btSalvar;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jtfAnoSemestre;
    private javax.swing.JTextField jtfCod_avaliacao;
    private javax.swing.JTextField jtfCod_curso;
    private javax.swing.JTextField jtfCod_pessoa;
    private javax.swing.JTextField jtfCod_turma;
    private javax.swing.JTextField jtfDesc_avaliacao;
    private javax.swing.JTextField jtfDesc_pessoa;
    // End of variables declaration//GEN-END:variables

}
